package object_test;

/**
 * @author yuisama
 * @date 2022/05/05 21:35
 **/
public class DeepTest {
    public static void main(String[] args) {
        B b1 = new B();
        B b2 = b1.clone();
        System.out.println(b1 == b2);
        System.out.println(b1.a == b2.a);
        b1.a.num = 100;
        System.out.println(b2.a.num);
    }
}
class A implements Cloneable{
    int num;
    public A clone() {
        A a = null;
        try {
            a = (A) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        return a;
    }
}

class B implements Cloneable {
    A a = new A();

    public B clone() {
        B newB = null;
        try {
            newB = (B) super.clone();
            newB.a = newB.a.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        return newB;
    }
}
